<?php
!defined('IN_APP') && exit('Access Denied');

define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
require APP_ROOT.'/lib/db.class.php';
require APP_ROOT.'/lib/global.func.php';
require APP_ROOT.'/lib/cache.class.php';
require APP_ROOT.'/model/base.class.php';
require APP_ROOT.'/config.php';

class app {

    var $get  = array();
    var $post = array();

    function __construct() {
        $this->init();
        $this->run();
    }

    function init() {
        header('Content-type: text/html; charset=UTF-8');
        $this->get=taddslashes($_GET);
        $this->post=taddslashes($_POST);
        empty($this->get['c']) && $this->get['c']='index';
        empty($this->get['a']) && $this->get['a']='default';
		unset($GLOBALS, $_ENV, $_GET, $_POST);
		//load control...
		$controlfile=APP_ROOT.'/control/'.$this->get['c'].'.php';
		$isadmin= ('admin'==substr($this->get['c'],0,5));
        $isadmin && $controlfile=APP_ROOT.'/control/admin/'.substr($this->get['c'],6).'.php';
        if(false===@include($controlfile)) {
            $this->notfound('control file "'.$controlfile.'" not found!');
        }
    }

    function run() {
        $controlname=$this->get['c'].'control';
        $control = new $controlname($this->get,$this->post);
        $method='on'.$this->get['a'];
        if(method_exists($control, $method)) {
            $regular=$this->get['c'].'-'.$this->get['a'];
            $isajax=(0===strpos($this->get['a'],'ajax'));
            if($control->checkable($regular) || $isajax) {
                $control->$method();
            }else {
               // $control->message('您无权进行当前操作，原因如下：<br/> 您所在的用户组('.$control->user['grouptitle'].')无法进行此操作。','user/login');
                exit("无权访问!");
            }
        }else {
            $this->notfound('method "'.$method.'" not found!');
        }
    }

	function notfound($error){
		@header('HTTP/1.0 404 Not Found');
		exit("<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\"><html><head><title>404 Not Found</title></head><body><h1>404 Not Found</h1><p> $error </p></body></html>");
	}
}


?>